{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Name</th>\n",
       "      <th>Platform</th>\n",
       "      <th>Year</th>\n",
       "      <th>Genre</th>\n",
       "      <th>Publisher</th>\n",
       "      <th>NA_Sales</th>\n",
       "      <th>EU_Sales</th>\n",
       "      <th>JP_Sales</th>\n",
       "      <th>Other_Sales</th>\n",
       "      <th>Global_Sales</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Wii Sports</td>\n",
       "      <td>Wii</td>\n",
       "      <td>2006.0</td>\n",
       "      <td>Sports</td>\n",
       "      <td>Nintendo</td>\n",
       "      <td>41.49</td>\n",
       "      <td>29.02</td>\n",
       "      <td>3.77</td>\n",
       "      <td>8.46</td>\n",
       "      <td>82.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Super Mario Bros.</td>\n",
       "      <td>NES</td>\n",
       "      <td>1985.0</td>\n",
       "      <td>Platform</td>\n",
       "      <td>Nintendo</td>\n",
       "      <td>29.08</td>\n",
       "      <td>3.58</td>\n",
       "      <td>6.81</td>\n",
       "      <td>0.77</td>\n",
       "      <td>40.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Mario Kart Wii</td>\n",
       "      <td>Wii</td>\n",
       "      <td>2008.0</td>\n",
       "      <td>Racing</td>\n",
       "      <td>Nintendo</td>\n",
       "      <td>15.85</td>\n",
       "      <td>12.88</td>\n",
       "      <td>3.79</td>\n",
       "      <td>3.31</td>\n",
       "      <td>35.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Wii Sports Resort</td>\n",
       "      <td>Wii</td>\n",
       "      <td>2009.0</td>\n",
       "      <td>Sports</td>\n",
       "      <td>Nintendo</td>\n",
       "      <td>15.75</td>\n",
       "      <td>11.01</td>\n",
       "      <td>3.28</td>\n",
       "      <td>2.96</td>\n",
       "      <td>33.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Pokemon Red/Pokemon Blue</td>\n",
       "      <td>GB</td>\n",
       "      <td>1996.0</td>\n",
       "      <td>Role-Playing</td>\n",
       "      <td>Nintendo</td>\n",
       "      <td>11.27</td>\n",
       "      <td>8.89</td>\n",
       "      <td>10.22</td>\n",
       "      <td>1.00</td>\n",
       "      <td>31.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16593</th>\n",
       "      <td>16596</td>\n",
       "      <td>Woody Woodpecker in Crazy Castle 5</td>\n",
       "      <td>GBA</td>\n",
       "      <td>2002.0</td>\n",
       "      <td>Platform</td>\n",
       "      <td>Kemco</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16594</th>\n",
       "      <td>16597</td>\n",
       "      <td>Men in Black II: Alien Escape</td>\n",
       "      <td>GC</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>Shooter</td>\n",
       "      <td>Infogrames</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16595</th>\n",
       "      <td>16598</td>\n",
       "      <td>SCORE International Baja 1000: The Official Game</td>\n",
       "      <td>PS2</td>\n",
       "      <td>2008.0</td>\n",
       "      <td>Racing</td>\n",
       "      <td>Activision</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16596</th>\n",
       "      <td>16599</td>\n",
       "      <td>Know How 2</td>\n",
       "      <td>DS</td>\n",
       "      <td>2010.0</td>\n",
       "      <td>Puzzle</td>\n",
       "      <td>7G//AMES</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16597</th>\n",
       "      <td>16600</td>\n",
       "      <td>Spirits &amp; Spells</td>\n",
       "      <td>GBA</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>Platform</td>\n",
       "      <td>Wanadoo</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>16598 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Rank                                              Name Platform  \\\n",
       "0          1                                        Wii Sports      Wii   \n",
       "1          2                                 Super Mario Bros.      NES   \n",
       "2          3                                    Mario Kart Wii      Wii   \n",
       "3          4                                 Wii Sports Resort      Wii   \n",
       "4          5                          Pokemon Red/Pokemon Blue       GB   \n",
       "...      ...                                               ...      ...   \n",
       "16593  16596                Woody Woodpecker in Crazy Castle 5      GBA   \n",
       "16594  16597                     Men in Black II: Alien Escape       GC   \n",
       "16595  16598  SCORE International Baja 1000: The Official Game      PS2   \n",
       "16596  16599                                        Know How 2       DS   \n",
       "16597  16600                                  Spirits & Spells      GBA   \n",
       "\n",
       "         Year         Genre   Publisher  NA_Sales  EU_Sales  JP_Sales  \\\n",
       "0      2006.0        Sports    Nintendo     41.49     29.02      3.77   \n",
       "1      1985.0      Platform    Nintendo     29.08      3.58      6.81   \n",
       "2      2008.0        Racing    Nintendo     15.85     12.88      3.79   \n",
       "3      2009.0        Sports    Nintendo     15.75     11.01      3.28   \n",
       "4      1996.0  Role-Playing    Nintendo     11.27      8.89     10.22   \n",
       "...       ...           ...         ...       ...       ...       ...   \n",
       "16593  2002.0      Platform       Kemco      0.01      0.00      0.00   \n",
       "16594  2003.0       Shooter  Infogrames      0.01      0.00      0.00   \n",
       "16595  2008.0        Racing  Activision      0.00      0.00      0.00   \n",
       "16596  2010.0        Puzzle    7G//AMES      0.00      0.01      0.00   \n",
       "16597  2003.0      Platform     Wanadoo      0.01      0.00      0.00   \n",
       "\n",
       "       Other_Sales  Global_Sales  \n",
       "0             8.46         82.74  \n",
       "1             0.77         40.24  \n",
       "2             3.31         35.82  \n",
       "3             2.96         33.00  \n",
       "4             1.00         31.37  \n",
       "...            ...           ...  \n",
       "16593         0.00          0.01  \n",
       "16594         0.00          0.01  \n",
       "16595         0.00          0.01  \n",
       "16596         0.00          0.01  \n",
       "16597         0.00          0.01  \n",
       "\n",
       "[16598 rows x 11 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas\n",
    "df = pandas.read_csv(\"vgsales.csv\")\n",
    "df  # 数据框架"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(16598, 11)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape    # 数据形状"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Year</th>\n",
       "      <th>NA_Sales</th>\n",
       "      <th>EU_Sales</th>\n",
       "      <th>JP_Sales</th>\n",
       "      <th>Other_Sales</th>\n",
       "      <th>Global_Sales</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>16598.000000</td>\n",
       "      <td>16327.000000</td>\n",
       "      <td>16598.000000</td>\n",
       "      <td>16598.000000</td>\n",
       "      <td>16598.000000</td>\n",
       "      <td>16598.000000</td>\n",
       "      <td>16598.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>8300.605254</td>\n",
       "      <td>2006.406443</td>\n",
       "      <td>0.264667</td>\n",
       "      <td>0.146652</td>\n",
       "      <td>0.077782</td>\n",
       "      <td>0.048063</td>\n",
       "      <td>0.537441</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>4791.853933</td>\n",
       "      <td>5.828981</td>\n",
       "      <td>0.816683</td>\n",
       "      <td>0.505351</td>\n",
       "      <td>0.309291</td>\n",
       "      <td>0.188588</td>\n",
       "      <td>1.555028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1980.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.010000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>4151.250000</td>\n",
       "      <td>2003.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.060000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>8300.500000</td>\n",
       "      <td>2007.000000</td>\n",
       "      <td>0.080000</td>\n",
       "      <td>0.020000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.010000</td>\n",
       "      <td>0.170000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>12449.750000</td>\n",
       "      <td>2010.000000</td>\n",
       "      <td>0.240000</td>\n",
       "      <td>0.110000</td>\n",
       "      <td>0.040000</td>\n",
       "      <td>0.040000</td>\n",
       "      <td>0.470000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>16600.000000</td>\n",
       "      <td>2020.000000</td>\n",
       "      <td>41.490000</td>\n",
       "      <td>29.020000</td>\n",
       "      <td>10.220000</td>\n",
       "      <td>10.570000</td>\n",
       "      <td>82.740000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Rank          Year      NA_Sales      EU_Sales      JP_Sales  \\\n",
       "count  16598.000000  16327.000000  16598.000000  16598.000000  16598.000000   \n",
       "mean    8300.605254   2006.406443      0.264667      0.146652      0.077782   \n",
       "std     4791.853933      5.828981      0.816683      0.505351      0.309291   \n",
       "min        1.000000   1980.000000      0.000000      0.000000      0.000000   \n",
       "25%     4151.250000   2003.000000      0.000000      0.000000      0.000000   \n",
       "50%     8300.500000   2007.000000      0.080000      0.020000      0.000000   \n",
       "75%    12449.750000   2010.000000      0.240000      0.110000      0.040000   \n",
       "max    16600.000000   2020.000000     41.490000     29.020000     10.220000   \n",
       "\n",
       "        Other_Sales  Global_Sales  \n",
       "count  16598.000000  16598.000000  \n",
       "mean       0.048063      0.537441  \n",
       "std        0.188588      1.555028  \n",
       "min        0.000000      0.010000  \n",
       "25%        0.000000      0.060000  \n",
       "50%        0.010000      0.170000  \n",
       "75%        0.040000      0.470000  \n",
       "max       10.570000     82.740000  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()   # 数据描述"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 'Wii Sports', 'Wii', ..., 3.77, 8.46, 82.74],\n",
       "       [2, 'Super Mario Bros.', 'NES', ..., 6.81, 0.77, 40.24],\n",
       "       [3, 'Mario Kart Wii', 'Wii', ..., 3.79, 3.31, 35.82],\n",
       "       ...,\n",
       "       [16598, 'SCORE International Baja 1000: The Official Game', 'PS2',\n",
       "        ..., 0.0, 0.0, 0.01],\n",
       "       [16599, 'Know How 2', 'DS', ..., 0.0, 0.0, 0.01],\n",
       "       [16600, 'Spirits & Spells', 'GBA', ..., 0.0, 0.0, 0.01]],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values   # 数据数组表示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method NDFrame.head of     age  gender      genre\n",
       "0    20       1     HipHop\n",
       "1    23       1     HipHop\n",
       "2    25       1     HipHop\n",
       "3    26       1       Jazz\n",
       "4    29       1       Jazz\n",
       "5    30       1       Jazz\n",
       "6    31       1  Classical\n",
       "7    33       1  Classical\n",
       "8    37       1  Classical\n",
       "9    20       0      Dance\n",
       "10   21       0      Dance\n",
       "11   25       0      Dance\n",
       "12   26       0   Acoustic\n",
       "13   27       0   Acoustic\n",
       "14   30       0   Acoustic\n",
       "15   31       0  Classical\n",
       "16   34       0  Classical\n",
       "17   35       0  Classical>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pandas.read_csv(\"music.csv\")\n",
    "df.head"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "0.37937959106836583\n",
      "3.946880132588812\n",
      " \n",
      "87\n",
      "[1, 3, 7, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "print(random.randint(1,10) )        # 产生 1 到 10 的一个整数型随机数  \n",
    "print(random.random() )             # 产生 0 到 1 之间的随机浮点数\n",
    "print( random.uniform(1.1,5.4) )     # 产生  1.1 到 5.4 之间的随机浮点数，区间可以不是整数\n",
    "print( random.choice('Hello, World!') )   # 从序列中随机选取一个元素\n",
    "print( random.randrange(1,100,2) )   # 生成从1到100的间隔为2的随机整\n",
    "\n",
    "a=[1,3,5,6,7]                # 将序列a中的元素顺序打乱\n",
    "random.shuffle(a)\n",
    "print(a)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "d80dceb8e76061e928794bb3ce8fa9d0c2b7abe9c550ab61d3fca5a520d3bcb0"
  },
  "kernelspec": {
   "display_name": "Python 3.8.6 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
